package com.fashion.web.actions;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fashion.model.News;
import com.fashion.model.NewsColumn;
import com.fashion.service.ColumnService;
import com.fashion.service.NewsService;
import com.fashion.utils.NewsTemplate;
import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller
@Namespace("/luxury")
public class LuxuryAction extends ActionSupport {
    List<News> focusNews = new ArrayList<News>();
    List<News> watchNews = new ArrayList<News>();
    List<News> specialNews = new ArrayList<News>();
    List<News> videoNews = new ArrayList<News>();
    List<News> jewelleryNews = new ArrayList<News>();
    List<News> artNews = new ArrayList<News>();
    List<News> carNews = new ArrayList<News>();
    List<News> planeNews = new ArrayList<News>();
    List<News> yachtNews = new ArrayList<News>();
    List<News> luxurySpecialNews = new ArrayList<News>();
    List<News> activityNews = new ArrayList<News>();
    private static final Logger logger = Logger.getLogger(LuxuryAction.class);
    private  NewsColumn column;

    @Resource(name = "newsService")
    private NewsService newsService;
    @Resource(name = "columnService")
    private ColumnService columnService;

    @Action(value = "index", results = {@Result(name = SUCCESS, location = "index.jsp"), @Result(name = ERROR, location = "../error.jsp")})
    public String index() throws Exception {
        try {
            List<NewsTemplate> templates = new ArrayList<NewsTemplate>();
            // focus news
            templates.add(new NewsTemplate(5, 6));
            NewsColumn focusColumn = columnService.findColumnByUrl("luxury",
                    "luxury");
            column = focusColumn;
            List<NewsColumn> focusColumns = columnService
                    .getAllChildren(focusColumn);
            focusColumns.add(focusColumn);
            focusNews = newsService.searchNewsByColumnListAndTemplateList(
                    focusColumns, templates, 1);
            // watchNews
            templates.clear();
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 3));
            templates.add(new NewsTemplate(2, 6));
            NewsColumn watchColumn = columnService.findColumnByUrl("luxury",
                    "wanbiao");
            List<NewsColumn> watchColumns = columnService
                    .getAllChildren(watchColumn);
            watchColumns.add(watchColumn);
            watchNews = newsService.searchNewsByColumnListAndTemplateList(
                    watchColumns, templates, 1);
            // specialNews
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 3));
            NewsColumn specialColumn = columnService.findColumnByUrl("special",
                    "luxury");
            List<NewsColumn> specialColumns = columnService
                    .getAllChildren(specialColumn);
            specialColumns.add(specialColumn);
            specialNews = newsService.searchNewsByColumnListAndTemplateList(
                    specialColumns, templates, 1);

            templates.clear();
            NewsColumn luxurySpecialColumn = columnService.findColumnByUrl(
                    "special", "luxury");
            List<NewsColumn> luxurySpecialColumns = columnService
                    .getAllChildren(luxurySpecialColumn);
            luxurySpecialColumns.add(luxurySpecialColumn);
            templates.add(new NewsTemplate(4, 4));
            luxurySpecialNews = newsService.searchNewsByColumnListAndTemplateList(
                    luxurySpecialColumns, templates, 1);

            // videoNews
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            NewsColumn videoColumn = columnService.findColumnByUrl("video",
                    "luxury");
            List<NewsColumn> videoColumns = columnService
                    .getAllChildren(videoColumn);
            videoColumns.add(videoColumn);
            videoNews = newsService.searchNewsByColumnListAndTemplateList(
                    videoColumns, templates, 1);
            // jewelleryNews
            templates.clear();
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 6));
            NewsColumn jewelleryColumn = columnService.findColumnByUrl("luxury",
                    "zhubao");
            List<NewsColumn> jewelleryColumns = columnService
                    .getAllChildren(jewelleryColumn);
            jewelleryColumns.add(jewelleryColumn);
            jewelleryNews = newsService.searchNewsByColumnListAndTemplateList(
                    jewelleryColumns, templates, 1);
            // artNews
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 2));
            templates.add(new NewsTemplate(2, 5));
            NewsColumn artColumn = columnService.findColumnByUrl("luxury",
                    "shoucang");
            List<NewsColumn> artColumns = columnService.getAllChildren(artColumn);
            artColumns.add(artColumn);
            artNews = newsService.searchNewsByColumnListAndTemplateList(artColumns,
                    templates, 1);
            // carNews
            templates.clear();
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 4));
            templates.add(new NewsTemplate(2, 2));
            templates.add(new NewsTemplate(1, 12));
            NewsColumn carColumn = columnService.findColumnByUrl("luxury",
                    "mingche");
            List<NewsColumn> carColumns = columnService.getAllChildren(carColumn);
            carColumns.add(carColumn);
            carNews = newsService.searchNewsByColumnListAndTemplateList(carColumns,
                    templates, 1);
            // planeNews
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 3));
            NewsColumn planeColumn = columnService.findColumnByUrl("luxury",
                    "feiji");
            List<NewsColumn> planeColumns = columnService
                    .getAllChildren(planeColumn);
            planeColumns.add(planeColumn);
            planeNews = newsService.searchNewsByColumnListAndTemplateList(
                    planeColumns, templates, 1);
            // yachtNews
            templates.clear();
            templates.add(new NewsTemplate(4, 1));
            templates.add(new NewsTemplate(3, 3));
            NewsColumn yachtColumn = columnService.findColumnByUrl("luxury",
                    "youting");
            List<NewsColumn> yachtColumns = columnService
                    .getAllChildren(yachtColumn);
            yachtColumns.add(yachtColumn);
            yachtNews = newsService.searchNewsByColumnListAndTemplateList(
                    yachtColumns, templates, 1);
            // 活动
            templates.clear();
            NewsColumn activityColumn = columnService.findColumnByUrl("activity",
                    "activity");
            List<NewsColumn> activityColumns = columnService
                    .getAllChildren(activityColumn);
            activityColumns.add(activityColumn);
            templates.add(new NewsTemplate(4, 2));
            templates.add(new NewsTemplate(3, 4));
            activityNews = newsService.searchNewsByColumnListAndTemplateList(activityColumns, templates, 1);

            return SUCCESS;
        } catch (Exception e) {
            logger.error("Error luxuryIndexAction: ", e);

            return ERROR;
        }
    }

    public List<News> getFocusNews() {
        return focusNews;
    }

    public List<News> getWatchNews() {
        return watchNews;
    }

    public List<News> getSpecialNews() {
        return specialNews;
    }

    public List<News> getVideoNews() {
        return videoNews;
    }

    public List<News> getJewelleryNews() {
        return jewelleryNews;
    }

    public List<News> getArtNews() {
        return artNews;
    }

    public List<News> getCarNews() {
        return carNews;
    }

    public List<News> getPlaneNews() {
        return planeNews;
    }

    public List<News> getYachtNews() {
        return yachtNews;
    }

    public List<News> getLuxurySpecialNews() {
        return luxurySpecialNews;
    }

    public List<News> getActivityNews() {
        return activityNews;
    }

    public NewsColumn getColumn() {
        return column;
    }

    public void setColumn(NewsColumn column) {
        this.column = column;
    }
}
